package com.swipemaster.network;

import org.json.JSONException;
import org.json.JSONObject;

import com.swipemaster.record.ChallengeRecord;
import com.swipemaster.record.IntegerRecord;
import com.swipemaster.record.RecordId;
import com.swipemaster.record.SurvivalRecord;

public class WorldRecord
{
	public String username;
	public double time;
	public int level;
	public int type;

	public WorldRecord(JSONObject json)
	{
		try
		{
			type = json.getInt("type");
			username = json.getString("username");
			time = json.getDouble("time");
			level = json.getInt("level");
		}
		catch (final JSONException e)
		{
			e.printStackTrace();
		}
	}

	@Override
	public String toString()
	{
		if (type == RecordId.CUSTOM_GAME)
		{
			final IntegerRecord record = new IntegerRecord(type);
			record.counter = (int) time;
			return record.toString();
		}
		if (type == RecordId.CHALLENGE)
		{
			final ChallengeRecord record = new ChallengeRecord();
			record.time = time;
			record.lastLevelIndex = level;
			return record.toString();
		}
		final SurvivalRecord record = new SurvivalRecord(type);
		record.time = time;
		return record.toString();
	}
}
